package com.huangpeng.designmodel.responsibility;

import com.huangpeng.designmodel.entity.Goods;
import com.huangpeng.designmodel.entity.Tax;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

/**
 * @Author huangpeng
 * @Title 具体回执处理者
 * @Package
 * @Date 2020/10/21 14:51
 * @Description 具体回执处理者
 * @Version 1.0
 */
public class PersonalIncomeTaxReceiptHandler implements IReceiptHandler {
    @Override
    public void handleReceipt(Tax tax, List<Goods> list, IReceiptHandleChain handleChain) {
        if(Objects.equals("PERSON_INCOME_TAX",tax.getTaxType())){
            System.out.println("###########当前计算税费类型-" + tax.getTaxType() + "，税费名称：" + tax.getTaxName() + ",税率：" + tax.getTaxRate());
            BigDecimal totalPrice = list.stream().filter(s -> Objects.nonNull(s.getGoodsPrice())).map(Goods::getGoodsPrice).reduce(BigDecimal.ZERO,BigDecimal::add);
            //计算税费
            BigDecimal taxRate = tax.getTaxRate();
            BigDecimal taxMoney = totalPrice.multiply(taxRate);
            String msg = String.format("按照当前税费类型需要缴纳的税费金额为：%s",taxMoney);
            System.out.println(msg);
        }else{//处理不了该回执就往下传递
            handleChain.handleReceipt(tax,list);
        }
    }
}
